/*
  Copyright (C) 2013 Napspirit / Thierry Rochelet

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
  
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


package com.napspirit.tmx.ui;

import java.awt.*;
import java.util.*;
import javax.swing.*;

import com.napspirit.tmx.data.TMXTU;

public class TMXTUCellRenderer extends JLabel implements ListCellRenderer<Object> {

    public TMXTUCellRenderer() {
        this.setOpaque(true);
        this.setText("");
    }

    public Component getListCellRendererComponent(JList<?> list, Object value, int index,boolean isSelected,boolean cellHasFocus) {
        // Object must be a TMXTU !
        TMXTU tu = (TMXTU)value;
        this.setText(tu.getID());


        Color background = Color.WHITE;
        Color foreground = Color.BLACK;

        if (isSelected) {
            background = Color.RED;
            foreground = Color.WHITE;
        } else {
            foreground = Color.BLACK;
            if (tu.isModified()) {
                background = Color.GREEN;
            }
            else {
                background = Color.WHITE;
            }
        }
        
        this.setBackground(background);
        this.setForeground(foreground);
        
        return this;
    }

}
